package com.buddy.summary.code.file;

import com.buddy.summary.code.utils.FileUtil;
import com.buddy.summary.code.utils.ReadXmlUtil;
import com.buddy.summary.code.utils.WriteXmlUtil;
import org.dom4j.Document;
import org.dom4j.Element;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class UpdateXmlTest2 {
    private static final Logger logger = LoggerFactory.getLogger(UpdateXmlTest2.class);

//    private static final String path = "/media/boyun/v/每日优鲜/over/lz_168";
//    private static final String path = "/media/boyun/v/每日优鲜/over/msy_186";
//    private static final String path = "/media/boyun/v/每日优鲜/over/rdg_145";
//    private static final String path = "/media/boyun/v/每日优鲜/over/wt_99";
//    private static final String path = "/media/boyun/v/每日优鲜/over/yl_329";
//    private static final String path = "/media/boyun/v/每日优鲜/over/yss_129";
//    private static final String path = "/media/boyun/v/每日优鲜/over/zhl_171";
//    private static final String path = "/media/boyun/v/每日优鲜/over/zyx_200";
    private static final String path = "/media/boyun/v/每日优鲜/over/wzp_181";
    private static Set<String> set = new LinkedHashSet();

    @Test
    public void getAllXmlFiles(){
        List<File> files = FileUtil.getFileList(new File(path),new ArrayList<>(),".xml");
        for (File file : files){
            try {
                this.updateXml(file.getAbsolutePath());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        for (String text : set){
            logger.info(text);
        }
    }
    public void updateXml(String xmlPath) throws IOException {
        Document document = ReadXmlUtil.getXMLByFilePath(xmlPath);
        Element root = document.getRootElement();
        List<Element> elementList = root.elements("object");
        for (Element objectElement : elementList){
            Element element = objectElement.element("name");
            String text = element.getText();
//            set.add(text);
            if (text.contains("巴黎矿泉水")){
                element.setText("blkqs");
            }else if (text.contains("三元")&&text.contains("牛奶")){
                element.setText("sycnn");
            }else if (text.contains("维他")&&text.contains("柠檬茶")){
                element.setText("wtmnmc");
            }else if (text.contains("airsnow轻爱原味")){//新希望airsnow轻爱原味
                element.setText("xxwairsnowqaywsn");
            }else if (text.contains("酸梅汤")){
                //信远斋
                element.setText("xyzsmt");
            }else if (text.contains("苏打水")){//屈臣氏苏打水
                element.setText("qcssds");
            }else if (text.contains("NFC橙汁")){//农夫NFC橙汁
                element.setText("nfNFCcz");
            }else if (text.contains("阿萨姆奶茶")){
                element.setText("asmnc");
            }else if (text.contains("脉动")){
                element.setText("mdqn");
            }else if (text.contains("农夫山泉柚子绿茶")){
                element.setText("nfsqyzlc");
            }else if (text.contains("伊利纯牛奶")){
                element.setText("ylcnn");
            }else if (text.contains("果粒橙")){//美汁源果粒橙
                element.setText("mzyglc");
            }else if (text.contains("农夫山泉矿泉水")){
                element.setText("nfsqkqs");
            }else if (text.contains("兰芳园丝袜奶茶")){
//                element.setText("lfyswnc280ml");
                element.setText("xyzsmt");
            }else if (text.contains("三得利乌龙茶")){
                element.setText("sdlwlc");
            }else if (text.contains("可口可乐")){
                element.setText("kkklg");
            }else if (text.contains("沙棘汁")){//吕梁野山坡沙棘汁饮料
                element.setText("llyspsjzyl350ml");
            }else if (text.contains("雀巢")){
                element.setText("qcshnt");
            }else if (text.contains("百岁山矿泉水")){
                element.setText("bsskqs");
            }else if (text.contains("北冰洋")){//汽水
                element.setText("bbyqs");
            }else if (text.contains("红牛")){
                element.setText("hn");
            }else if (text.contains("新希望香蕉牛奶")){
                element.setText("xxwxjnn");
            }else if (text.contains("蒙牛纯牛奶250ml")){
                element.setText("mncnn250ml");
            }else if (text.contains("摩奇")){
                element.setText("mqtzyl250ml");
            }else if (text.contains("统一绿茶")){
                element.setText("tylc");
            }else if (text.contains("屈臣氏香草味苏打汽水")){
                element.setText("qcsxcwsdqs");
            }else{
                set.add(text);
            }
            WriteXmlUtil.writeXMLToFile(document,xmlPath);
        }
    }
    

}
